<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
	<!--<![endif]-->
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>手机快捷登录</title>
		<meta name="description" content="">
		<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
		<meta content="telephone=no" name="format-detection" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />

		<!-- 引入样式 -->
		<link rel="stylesheet" href="../styles/vant.css">
		<link rel="stylesheet" href="../styles/common.css" />
		<link rel="stylesheet" href="../styles/global.css" />
		<link rel="stylesheet" href="../styles/login.css" />
		<link rel="stylesheet" href="../styles/font.css">
		<!-- 引入组件 -->
		<script src="../scripts/babel.js" type="text/javascript" charset="utf-8"></script>
		<script src="../scripts/rem.js"></script>		
		<script src="../scripts/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="../scripts/vant.js"></script>
		<script src="../scripts/api.js" type="text/javascript" charset="utf-8"></script>
		<script src="../scripts/axios.js" charset="utf-8"></script>
	</head>
	<body>
		<!--[if lt IE 7]>
            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

		<div class="container" id="app">
			<!-- <div class="header">
                <div><i class="iconfont icon-back"></i></div>
                <div>快捷登录</div>
                <div class="headericon"></div>
            </div> -->
			<h1 class="title">验证码快捷登录</h1>
			<div class="form">
				<div class="iteminput"><input type="text" placeholder="请输入手机号" name="" v-model="tel"></div>
				<div class="iteminput">
					<input type="text" maxlength="6" placeholder="请输入验证码" name="" v-model="verifcode">
					<!-- <van-button type="default" size="mini">默认按钮</van-button> -->
					<a @click="send_code" href="javascript:;" class="sendcode" v-text="tips"></a>
				</div>
				<div style="padding-top:1rem;">
					<button @click="login" class="button">登 录</button>
				</div>
				<div class="loginc">
					<a @click="login_tel" href="javascript:;">账号密码登录</a>
					<a href="../repassword.html">忘记密码</a>
				</div>
			</div>
		</div>
	</body>
	<script type="text/babel">
		new Vue({
			el: '#app',
			data: {
				url: "",
				tel: "",
				verifcode: "",
				tips: "发送验证码",
				timer: null,
				count:"",
				teltype:"",
			},
			//计算属性
			computed: {},
			created: function() {},
			mounted: function() {
				var admin = localStorage.getItem("admin")?JSON.parse(localStorage.getItem("admin")):''	;
				if(admin&&admin!=''){
					window.location.href='index.html';
					return
				}
				this.url = url();
				this.open_az();
			},
			computed: {},
			methods: {
				////判断操作系统
				open_az: function() {
					var that =this;					
					//判断操作系统
					var u = navigator.userAgent,
						app = navigator.appVersion;
					var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
					var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
					//	           ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端         
					if(isAndroid) {
						that.teltype = 1;					
					}
					if(isIOS) {　　　　 //这个是ios操作系统						
						that.teltype = 2;
					}
				},
				// 发送验证码
				send_code: function() {
					var that = this;
					if (that.tips != "发送验证码") {
						return
					}
					if (that.tel == '') {
						that.$notify("请输入手机号码");
						return false;
					};
					if (!(/^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/i.test(that.tel))) {
						that.$notify("手机格式不正确");
						return false;
					};
					var data = {
						tel: that.tel,
					}
					console.log(data)
					axios.post(that.url + '/no/mchappinfo/sendTelCodeForLogin', data).then(function(response) {							
							if (response.data.code == 200) {
								that.$notify(response.data.disp);
								that.tips_timer()
							}//判断单点登录
							else if(response.data.code == 300){
								that.$notify("账号在别处登录，将为您返回登录页面");//							
								if(that.admin.teltype==1){
									logout_app(that.admin.mid,1)
								}
								if(that.admin.teltype==2){
									logout_app(that.admin.mid,2)
								}							
							}  else {
								that.$notify(response.data.disp);
							}
						})
				},
				tips_timer() {
					var TIME_COUNT = 60;
					var that = this;
					if (!this.timer) {
						this.count = TIME_COUNT;						
						this.timer = setInterval(() => {
							if (this.count > 0 && this.count <= TIME_COUNT) {
								this.count--;
								that.tips = this.count + "秒后在发送"
							} else {								
								clearInterval(this.timer);
								that.tips = "发送验证码"
								this.timer = null;
							}
						}, 1000)
					}
				},				
				login: function() {
					// var reg = '/^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/i';
					var that = this;
					if (that.tel == '') {
						that.$notify("请输入手机号码");
						return false;
					}
					if (!(/^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/i.test(that.tel))) {
						that.$notify("手机格式不正确");
						return false;
					}
					if (that.verifcode == '') {
						that.$notify("请输入验证码");
						return false;
					}
					
					var data = {
						logintype: 2,
						tel: that.tel,
						verifcode: that.verifcode,
						teltype:that.teltype,
					}
					console.log(data)
					axios.post(that.url + '/no/mchappinfo/mchlogin', data)
						.then(function(response) {							
							if (response.data.code == 200) {
								localStorage.setItem("admin",JSON.stringify(response.data));
								window.location.href = "../index.html"
							}//判断单点登录
							else if(response.data.code == 300){
								that.$notify("账号在别处登录，将为您返回登录页面");//							
								if(that.admin.teltype==1){
									logout_app(that.admin.mid,1)
								}
								if(that.admin.teltype==2){
									logout_app(that.admin.mid,2)
								}	
								window.location.href ='../login.html';
							}  else {
								that.$notify(response.data.disp);
							}
						})
						
				},
				login_tel:function(){
					window.location.href = "../login.html"
				},
				
			},

		})
	</script>
</html>
